<?php
namespace app\pc\controller;
use think\Controller;
use think\Request;

use app\api\model\Goods as GoodsModel;

//首页
class Goods extends Common
{
    

    // 商品列表
    
    public function getGoodsList(Request $request){

        $user_id = $this->checkLoginUser();
       // $user_id =74;
        $page = $request->param('page',1);
        $cate = $request->param('goods_cate',0);
        to_json_encode(200,'success',GoodsModel::handleGoodsList(GoodsModel::getGoodsList($cate,$page,GoodsModel::GOODS_PC_PLAT),$user_id));

    }

    //商品分类列表
    public function getGoodsCateList(Request $request)
    {
        $res =[];
        $list = GoodsModel::getGoodsCateList(GoodsModel::GOODS_PC_PLAT);
        $i=$j=0;
        $m=-1;
        foreach ($list as $key=>$val)
        {
            if(false ===mb_strpos($val['cate_name'],'位计'))
            {
                $j=0;
                $res[$i++]=$val;

            }else{
                if($m==-1)
                {
                    $m=$i;
                    $res[$m]=['cate_name'=>'物位计','list'=>[]];
                    $i++;
                }

                $res[$m]['list'][$j]=$val;
                $j++;
            }
        }
        to_json_encode(200,'success',$res);

    }
    public function getGoodsInfo(Request $request)
    {
        $user_id = $this->checkLoginUser();

        //$user_id=74;
        $goods_id = $request->param('goods_id');
        $info = GoodsModel::getGoodsInfo($goods_id);
        if(empty($info))
        {
            to_json_encode(400,'error',['status'=>false]);
        }
        $info = GoodsModel::handleGoodsInfo($info,$user_id);
       // $info['points']=GoodsModel::getGoodsPoints($goods_id);

        to_json_encode(200,'success',$info);

    }
}
